﻿package com.example.Utils;
import java.util.ArrayList;
import java.util.List;

import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.ValueShape;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.LineChartView;
import android.graphics.Color;
import android.view.View;

public class Utilsquxian {
	private String[] timeGrapt = new String[24];
	private int[] tempGrapt = new int[24];

	public Line getLine(int[] pointArray) {
		Line line = new Line(getAxisPoints(pointArray));

		line.setColor(Color.parseColor("#80FFFF")); // 折线的颜色
		line.setShape(ValueShape.CIRCLE);// 折线图上每个数据点的形状 这里是圆形 （有三种
											// ：ValueShape.SQUARE
											// ValueShape.CIRCLE
											// ValueShape.SQUARE）
		line.setCubic(true);// 曲线是否平滑
		line.setStrokeWidth(1);// 线条的粗细，默认是3
		line.setFilled(false);// 是否填充曲线的面积
		line.setHasLabels(true);// 曲线的数据坐标是否加上备注
		// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
		line.setHasLines(true);// 是否用直线显示。如果为false 则没有曲线只有点显示
		line.setHasPoints(true);// 是否显示圆点 如果为false 则没有原点只有点显示
		return line;
	}

	public void initData(LineChartView lineChart, List<Line> lineList,
			String[] xline) {

		LineChartData data = new LineChartData();
		data.setLines(lineList);
		Axis axisY = new Axis(); // Y轴
		// axisY.setName("温度");// y轴标注
		axisY.setTextSize(11);// 设置字体大小

		Axis axisX = new Axis(); // X轴
		axisX.setHasTiltedLabels(false); // X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
		// axisX.setTextColor(Color.WHITE); //设置字体颜色
		axisX.setTextColor(Color.parseColor("#D6D6D9"));// 灰色
		axisX.setValues(getAxisXLables(xline));
		// axisX.setName("24小时预报"); //表格名称
		axisX.setTextSize(11);// 设置字体大小
		
		
	//	//axisX.setMaxLabelChars(7); // 最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
		axisX.setHasLines(true); // x 轴分割线
		data.setAxisXBottom(axisX); // x 轴在底部
		// data.setAxisXTop(axisX); //x 轴在顶部
		data.setValueLabelBackgroundEnabled(false);//字体设置为没有背景
		data.setAxisYLeft(axisY); // Y轴设置在左边
		// data.setAxisYRight(axisY); //y轴设置在右边
		// 设置行为属性，支持缩放、滑动以及平移
		lineChart.setInteractive(false);
		lineChart.setZoomType(ZoomType.HORIZONTAL); // 缩放类型，水平
		// lineChart.setMaxZoom((float) 3);// 缩放比例
		lineChart.setLineChartData(data);
		lineChart.setVisibility(View.VISIBLE);
		// Viewport v = new Viewport(lineChart.getMaximumViewport());
		// v.left = 0;
		// v.right = 7;
		// lineChart.setCurrentViewport(v);

	}

	/**
	 * X 轴的显示
	 */
	public List<AxisValue> getAxisXLables(String[] date) {
		// 坐标轴
		List<AxisValue> list = new ArrayList<AxisValue>();
		for (int i = 0; i < date.length; i++) {
			list.add(new AxisValue(i).setLabel(date[i]));
		}
		return list;
	}

	/**
	 * 图表的每个点的显示
	 */
	public List<PointValue> getAxisPoints(int[] score) {
		List<PointValue> list = new ArrayList<PointValue>();
		for (int i = 0; i < score.length; i++) {
			if (score[i] != 0) {
				list.add(new PointValue(i, score[i]));
			}
		}
		return list;
	}

	public void SetData(String time, int temp, int low, int high) {
		// TODO Auto-generiated method stub
		String[] st = { "01:00", "02:00", "03:00", "04:00", "05:00", "06:00",
				"07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00",
				"14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00",
				"21:00", "22:00", "23:00", "24:00" };// X轴的标注

		int num = 0;
		List<String> slist = new ArrayList<String>();
		for (int i = 0; i < st.length; i++) {
			if (st[i].equals(time)) {
				num = i;
			}
		}

		for (int i = num; i < st.length; i++) {

			if (i == num) {
				tempGrapt[0] = temp;
				slist.add("当前");
			} else
				slist.add(st[i]);
			if (i == 11) {
				tempGrapt[slist.size() - 1] = high;
			}
			if (i == 23) {
				tempGrapt[slist.size() - 1] = low;
			}
		}
		for (int i = 0; i < num; i++) {
			slist.add(st[i]);
			if (i == 11) {
				tempGrapt[slist.size() - 1] = high;
			}
			if (i == 23) {
				tempGrapt[slist.size() - 1] = low;
			}
		}
		for (int i = 0; i < st.length; i++) {
			timeGrapt[i] = slist.get(i);
		}

		if (num == 11 || num == 23) {
			tempGrapt[23] = temp;
			tempGrapt[0] = temp;
		} else if (num > 0) {
			tempGrapt[23] = temp;
		}

	}
}